<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <script src="https://cdn.jsdelivr.net/npm/vue@2.6.10/dist/vue.js"></script>
</head>
<body>
  <div id="app">
    <parent></parent>
  </div>
</body>
<script>

  // 类似于ElementUI框架
  var child = Vue.extend({
    template:`
      <div>
        <ul v-for="item in persons" :key="item.id">
          <slot :row="item"></slot>
        </ul>
      </div>
    `,
    props:['persons'],
    created(){
      console.log(this.persons)
    }
  })

  // Vue.component('child',child) // 全局注册

  // 自己写的组件，比如 用户列表组件 权限列表组件 商品列表组件
  Vue.component('parent',{
    template:`
      <div>
        <child :persons="persons">
            <template slot-scope="scope">
              <li :style="{'color':scope.row.tag =='bad' ? 'red' : 'green'}">{{scope.row.name}}---{{scope.row.address}}</li>
            </template>
        </child>
      </div>
    `,
    data(){
      return {
        persons:[
          {id:1001,name:'成昆',address:'光明顶',tag:'bad'},
          {id:1002,name:'张无忌',address:'环游世界',tag:'good'},
          {id:1003,name:'宋青书',address:'武当山',tag:'bad'},
          {id:1004,name:'尹志平',address:'终南山',tag:'good'}
        ]
      }
    },
    // 局部注册
    components:{
      'child':child
    }
  })

  var vm = new Vue({
    el:'#app'
  })
</script>
</html>
